﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 暑假作业
{
    class DBHelper
    {
        public static string ConnectionString = "server=.\\BIGBANG;database=storehouseDB;Integrated Security=true";
        //数据库连接对象
        public static SqlConnection conn = new SqlConnection(ConnectionString);
        //展示数据
        public static DataSet show(string sql)
        {
            SqlDataAdapter dap = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            dap.Fill(ds);
            if (ds.Tables[0].Rows.Count != 0)
            {
                return ds;
            }
            else
            {
                return ds;
            }
        }
        //增加更新
        public static int insert(string sql)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            if (cmd.ExecuteNonQuery() > 0)
            {
                conn.Close();
                return 1;

            }
            else
            {
                conn.Close();
                return 2;

            }
        }
    }
}
